package tool.zyk.spring.invoke;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import tool.zyk.invoke.AbstractReflectExecutor;

/**
 * author: zyk
 * datetime: 2024/2/3 00:20
 * describe:
 */
@Slf4j
public class SpringReflectExecutor extends AbstractReflectExecutor implements ApplicationContextAware {
    private static ApplicationContext applicationContext;

    @Override
    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        SpringReflectExecutor.applicationContext = applicationContext;
        log.debug("applicationContext:{}", applicationContext);
    }


    @Override
    protected <T> T getObj(Class<T> tClass) throws InstantiationException, IllegalAccessException {
        return applicationContext.getBean(tClass);
    }
}
